from selenium import webdriver
from time import sleep

from selenium.webdriver.support.select import Select

from page.base_page import BasePage


class Add_Coupon(BasePage):

    def add_coupon(self):
        # try:
            driver = webdriver.Chrome()
            driver.get('http://192.168.124.48/Admin')
            driver.implicitly_wait(4)
            # sleep(3)
            driver.maximize_window()
            driver.find_element_by_name('username').send_keys("admin")

            driver.find_element_by_name('password').send_keys("123456")

            driver.find_element_by_name('vertify').send_keys("8888")

            driver.find_element_by_name('submit').click()

            driver.find_element_by_xpath('/html/body/div[1]/div[4]/ul/li[2]/a').click()
            # 点击促销
            driver.find_element_by_link_text('促销').click()
            # 点击优惠券
            driver.find_element_by_link_text('优惠券').click()
            sleep(3)
            # 切换到iframe中
            iframe = driver.find_element_by_id('workspace')
            driver.switch_to.frame(iframe)
            sleep(4)
            # 点击添加优惠券
            driver.find_element_by_class_name('add').click()
            sleep(4)
            # 输入优惠券名称
            driver.find_element_by_id('name').send_keys("限时限量")
            # 输入优惠券面额
            driver.find_element_by_id('money').send_keys("100")
            # 输入消费金额
            driver.find_element_by_id('condition').send_keys("50")
            # 输入发放数量
            driver.find_element_by_id('createnum').send_keys("50")
            # 使用起始日期
            driver.find_element_by_id('use_start_time').clear()
            driver.find_element_by_id('use_start_time').send_keys('2021-11-10 15:25:20')
            # 使用结束日期
            driver.find_element_by_id('use_start_time').clear()
            driver.find_element_by_id('use_end_time').send_keys('2021-11-11 15:25:20')
            driver.find_element_by_xpath('//*[@id="handleposition"]/div/div/a').click()
            sleep(2)
            tips = driver.find_element_by_id('err_condition').text
            print(tips)
            assert tips == '消费金额不能小于或等于优惠券金额','断言失败'
            # 使用结束日期
            # driver.find_element_by_id('condition').send_keys("50")

            # driver.find_element_by_id('condition').send_keys("50")

            sleep(4)
            driver.close()
        # except Exception as e:
        #     print(e)
        # finally:
        #     self.close()



if __name__ == '__main__':
    Add_Coupon('Chrome').add_coupon()





































